/**
 * 
 */
package com.dsteiner.widgets.client.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.dsteiner.widgets.client.StringUtil;
import com.dsteiner.widgets.client.util.ValidationUtil.Error;

public class ValidationResults implements Error{
	private List<Error> errors = new ArrayList<Error>();
	
	public ValidationResults add(Error result){
		if(result != null && !StringUtil.isEmpty(result.getMessage()))
			errors.add(result);
		return this;
	}

	public boolean isEmpty() {
		return errors.isEmpty();
	}
	
	public String getMessage() {
		StringBuffer sb = new StringBuffer();
		for (Iterator<Error> iterator = errors.iterator(); iterator.hasNext();) {
			Error error = iterator.next();
			sb.append(error.getMessage());
			if(iterator.hasNext())
				sb.append("\n");
		}
		return sb.toString();
	}

	public boolean contains(String field) {
		for (Error error : errors) {
			if(error.contains(field))
				return true;
		}
		return false;
	}
}